<?php

/**
 * This is the model class for table "NEWS_FLASH".
 *
 * The followings are the available columns in table 'NEWS_FLASH':
 * @property integer $id_news_flash
 * @property string $image
 * @property integer $owner
 * @property string $notice
 * @property string $created_at
 * @property integer $id_admin
 *
 * The followings are the available model relations:
 * @property ADMINLOGIN $idAdmin
 * @property HAKAKSES $owner0
 */
class NEWSFLASH extends CActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @return NEWSFLASH the static model class
     */
    public static function model($className=__CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'NEWS_FLASH';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('created_at', 'default', 'value' => date('Y-m-d H:m:s')),
            array('owner', 'default', 'value' => base64_decode(Yii::app()->user->id)),
            array('id_admin', 'default', 'value' => base64_decode(Yii::app()->user->school)),
            array('notice', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id_news_flash, image, owner, notice, created_at, id_admin', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'idAdmin' => array(self::BELONGS_TO, 'ADMINLOGIN', 'id_admin'),
            'owner0' => array(self::BELONGS_TO, 'HAKAKSES', 'owner'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id_news_flash' => 'Id News Flash',
            'image' => 'Gambar',
            'owner' => 'Sumber Berita',
            'notice' => 'Catatan',
            'created_at' => 'Waktu Upload',
            'id_admin' => 'Admin Unit',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id_news_flash', $this->id_news_flash);
        $criteria->compare('image', $this->image, true);
        $criteria->compare('owner', $this->owner);
        $criteria->compare('notice', $this->notice, true);
        $criteria->compare('created_at', $this->created_at, true);
        $criteria->compare('id_admin', $this->id_admin);

        return new CActiveDataProvider($this, array(
                    'criteria' => $criteria,
                ));
    }

}